use std::io;
use sea_query::Iden;
use tracing::level_filters::LevelFilter;
use tracing_subscriber::{fmt, Layer, Registry};
use tracing_subscriber::fmt::time::ChronoLocal;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;


/// 为Cake实现[sea_query::Iden] trait
/// 
/// 展开后的代码
// impl sea_query::Iden for Cake {
//     fn prepare(&self, s: &mut dyn ::std::fmt::Write, q: sea_query::Quote) {
//         s.write_fmt(::core::format_args!("{}", q.left())).unwrap();
//         self.unquoted(s);
//         s.write_fmt(::core::format_args!("{}", q.right())).unwrap();
//     }
//     fn unquoted(&self, s: &mut dyn ::std::fmt::Write) {
//         match self {
//             Self::Table => s.write_fmt(::core::format_args!("{}", "cake")).unwrap(),
//             Self::Id => s.write_fmt(::core::format_args!("{}", "id")).unwrap(),
//             Self::Name => s.write_fmt(::core::format_args!("{}", "name")).unwrap()
//         };
//     }
// }
#[derive(Iden)]
pub enum Cake {
    Table,
    Id,
    Name,
}

#[derive(Iden)]
pub enum Fruit {
    Table,
    Id,
    Name,
    CakeId
}

/// 初始化日志
pub fn init_log() {
    let timer = ChronoLocal::new(String::from("%Y-%m-%d %H:%M:%S"));

    let console_layer = fmt::layer()
        // 自定义数据时间格式
        .with_timer(timer.clone())
        // 线程名
        .with_thread_names(true)
        // 输出到标准的成错误输出
        .with_writer(io::stderr)
        // 只记录INFO及以上级别的日志
        .with_filter(LevelFilter::DEBUG);
    // 注册
    Registry::default().with(console_layer).init();
}